package com.longbig.multifunction.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;


/**
 * @author Administrator
 * @date 2024/4/24 9:58
 * @description
 */
@Configuration
public class TaskExecutorConfig {

    @Bean(name = "singleTaskExecutor")
    public Executor singleTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(1); // 核心线程数
        executor.setMaxPoolSize(1);   // 最大线程数
        executor.setQueueCapacity(0);  // 队列容量
        executor.setThreadNamePrefix("single-task-"); // 线程名称前缀
        executor.initialize();
        return executor;
    }
}
